﻿using System;
using fastCSharp;

namespace diantou.web.contest
{
    /// <summary>
    /// 用户在比赛下的提交记录
    /// </summary>
    [fastCSharp.code.cSharp.webView(IsPool = true, IsReferer = false)]
    partial class submitList : view<submitList>
    {
        /// <summary>
        /// 用户问题提交综合信息
        /// </summary>
        [fastCSharp.code.cSharp.webView.clientType(Name = "diantou.problemJudge")]
        internal sealed class problemJudge : diantou.dataAccess.contestJudge.problemJudge
        {
            /// <summary>
            /// 用户问题标识
            /// </summary>
            [fastCSharp.code.cSharp.webView.outputAjax]
            public long Id;
            /// <summary>
            /// 问题
            /// </summary>
            public diantou.dataAccess.problem Problem;
            /// <summary>
            /// 
            /// </summary>
            public int Point;
            /// <summary>
            /// 用户标识
            /// </summary>
            public diantou.dataAccess.user User;
            /// <summary>
            /// 用户相关提交
            /// </summary>
            public userJudge UserJudge
            {
                get
                {
                    return new userJudge { Judge = Judge, UserId = User == null ? 0 : User.Id, IsAdmin = User != null && User.Permission == dataModel.user.permission.Admin };
                }
            }
            /// <summary>
            /// 用户问题提交综合信息
            /// </summary>
            public problemJudge() { }
            /// <summary>
            /// 用户问题提交综合信息
            /// </summary>
            /// <param name="value"></param>
            /// <param name="userId"></param>
            /// <param name="user"></param>
            public problemJudge(diantou.dataAccess.contestJudge.problemJudge value, int userId, diantou.dataAccess.user user)
            {
                Set(value, userId, user);
            }
            /// <summary>
            /// 设置问题提交综合信息
            /// </summary>
            /// <param name="value"></param>
            /// <param name="userId"></param>
            /// <param name="user"></param>
            public void Set(diantou.dataAccess.contestJudge.problemJudge value, int userId, diantou.dataAccess.user user)
            {
                Id = ((long)userId << 32) + value.ProblemId;
                if ((Judge = value.Judge).SubmitTime != value.Time)
                {
                    Judge.SubmitTime = value.Time;
                    Judge.Id = -value.ProblemId;
                }
                Count = value.Count;
                Point = Judge.GetPoint(Problem = diantou.dataAccess.clientCache.Problem[value.ProblemId]);
                User = user;
            }
            /// <summary>
            /// 清除问题提交综合信息
            /// </summary>
            public void Clear()
            {
                Judge = null;
                User = null;
            }
        }
        /// <summary>
        /// 用户提交问题列表
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        private new problemJudge[] problems;
        /// <summary>
        /// 用户信息
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        private diantou.dataAccess.user user;
        /// <summary>
        /// 用户的提交记录
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="contestId"></param>
        /// <param name="page">分页号</param>
        /// <returns>是否成功</returns>
        private bool loadView(int contestId, string randomCode, int userId, int page)
        {
            if (base.load(contestId, randomCode))
            {
                if (userId == 0 || (currentUser != null && currentUser.Id == userId)) user = currentUser;
                else user = diantou.dataAccess.clientCache.User[userId];
                if (user != null)
                {
                    diantou.dataAccess.contestJudge.problemJudge[] problemJudges = diantou.dataAccess.tcpCall.contestJudge.getUserProblems(user.Id, contestId);
                    problems = problemJudges.getArray(value => new problemJudge(value, user.Id, currentUser));
                    pageInfo.Count = problems.Length;
                    return true;
                }
                AjaxResponse(webConfig.NotFound404);
            }
            return false;
        }
    }
}
